package com.lanou3g.farmdoctor.widget;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lanou3g.farmdoctor.entity.greendao.RichDetailEntity;

/**
 * 本类由: Risky 创建于: 15/11/26.
 */
public class FamerToolbar extends Toolbar {
    private TextView leftText;
    private TextView middleText;
    private TextView rightText;
    private final Context context;
    public FamerToolbar(Context context) {
        this(context,null);
    }

    public FamerToolbar(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public FamerToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        init();
    }

    private void init() {
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
        lp.weight =1;
        LinearLayout ll = new LinearLayout(context);
        ll.setLayoutParams(lp);
        leftText = new TextView(context);
        leftText.setText("left");
        middleText = new TextView(context);
        middleText.setText("middle");
        rightText = new TextView(context);
        rightText.setText("right");
        middleText.setGravity(Gravity.CENTER);
        middleText.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);
        middleText.setTextColor(Color.WHITE);
        ll.addView(leftText,lp);
        ll.addView(middleText,lp);
        ll.addView(rightText,lp);
        addView(ll);
    }

    @Override
    public void setTitle(@StringRes int resId) {
        super.setTitle(resId);
    }

    @Override
    public void setTitle(CharSequence title) {
        super.setTitle("");
        middleText.setText(title);
    }
}
